/*  ------------------------------------------------------------------------  */
/*  Paper        : Does Stakeholder Outrage Determine Executive Pay?          */
/*  Program      : a02-03-lateIndustry.do                                     */
/*  Description  : Salary cuts by industry                                    */
/*  ------------------------------------------------------------------------  */

use "$temp112/outragePanel.dta", clear

sicff siccd, ind(12)

/*  ------------------------------------------------------------------------  */
//  Split the sample based on firm characteristics

foreach ff of numlist 1/12  {
gen fft_`ff' = (ff_12==`ff')
}

/*  ------------------------------------------------------------------------  */
//  Table output

foreach complvar of varlist fft_1-fft_12 {
foreach num of numlist 1  {

#delimit ;
di "------------------------------------" _newline 
"FE iteration  :   `complvar'" _newline
"------------------------------------"
; #delimit cr

local interact dcut_firm
local cluster vce(robust)
local ctrl fyear==2019 & mainsample_2020==1 
local qui qui

capture drop `complvar'_high
gen `complvar'_high = `complvar'

di _newline "-----------" _newline "First column" _newline "-----------"
eststo fft_`complvar'_first_`num': `qui' reg `interact' if `ctrl' & `complvar'_high==`num', `cluster'
estadd scalar probability = e(b)[1,_cons]

di _newline "-----------" _newline "Second column" _newline "-----------"

`qui' summ `complvar'_high if `complvar'_high == `num' & `ctrl'
local sub_`num' = r(N)
`qui' summ `complvar'_high if `ctrl'
local all = r(N)
local pxx_`num' = `sub_`num'' / `all'
	estadd scalar marginal = `pxx_`num''

di _newline "-----------" _newline "Third column" _newline "-----------"

`qui' summ `complvar'_high if `complvar'_high == 0 & `ctrl'
	local sub_0 = r(N)
`qui' summ `complvar'_high if `complvar'_high == 1 & `ctrl'
	local sub_1 = r(N)
`qui' summ `complvar'_high if `ctrl'
	local all = r(N)
	local pxx_0 = `sub_0' / `all'
	local pxx_1 = `sub_1' / `all'

`qui' summ `interact' if `ctrl', detail
	local p50 `r(p50)'
	local p90 `r(p99)'

`qui' reg `interact' if `ctrl' & `complvar'_high==0, `cluster'
	local beta_0 _b[_cons]
	local _compliers_0 = `beta_0' * (`p90' - `p50')
	local _pxx_and_complier_0 = `_compliers_0' * `pxx_0'

`qui' reg `interact' if `ctrl' & `complvar'_high==1, `cluster'
	local beta_1 _b[_cons]


local _compliers_1 = `beta_1' * (`p90' - `p50')
local _pxx_and_complier_1 = `_compliers_1' * `pxx_1'
local _pct_compliers = `_pxx_and_complier_0' + `_pxx_and_complier_1'
global pxx_complier_0 = `_pxx_and_complier_0' / `_pct_compliers'
global pxx_complier_1 = `_pxx_and_complier_1' / `_pct_compliers'
global pxx_ratio_0 = $pxx_complier_0 / `pxx_0'
global pxx_ratio_1 = $pxx_complier_1 / `pxx_1'


di _newline "-----------" _newline "Third column" _newline "-----------"
	estadd scalar complier = ${pxx_complier_`num'}

di _newline "-----------" _newline "Fourth column" _newline "-----------"
	estadd scalar likelihood = ${pxx_ratio_`num'}

capture drop `complvar'_high
}
}


/*  -|----------------------------------------------------------------------  */
/*  ||  ---    Program end: a02-03-lateIndustry.do                            */
/*  -|  ---    Attila Balogh    --------------------------------------------  */